﻿


$(document).ready(function () {
    $("#empCode").change(function () {
        $("#deptName").val("");
        $("#postName").val("");
        $("#txtEmployeeID").val("");
        $("#EmployeeID").val("");
        var empcode = $("#empCode").val();
        if (empcode == "") return;
        var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=EmployeeCode='" + empcode + "'&r=" + Math.random();
        $.get(url, function (d, s) {
            var list = eval("(" + d + ")");
            if (list.total > 0) {
                for (var o in list.rows) {
                    var empId = list.rows[o].ID;
                    var empName = list.rows[o].CName;
                    var dept = list.rows[o].DeptName;
                    var post = list.rows[o].PostName;
                    if (typeof (empcode) != "undefined") {
                        $("#deptName").val(dept);
                        $("#postName").val(post);
                        $("#txtEmployeeID").val(empName);
                        $("#EmployeeID").val(empId);
                        break;
                    }
                }
            }
        });
    });
    var tempDate = new Date();
    $("#year").val(tempDate.getFullYear());
    for (var i = 0; i < 12; i++) {
        $("#month").append("<option value='" + (i + 1) + "'>" + (i + 1) + "月</option>");
    }
    var employeeCode = getPar1("empcode");
    //修改时，隐藏选择按钮，并且工号不可编辑
    if (employeeCode != "") {
        $("#empCode").val(employeeCode).attr("readonly", true).css("background", "whitesmoke").trigger("change");
        $("#btnEmployeeID").hide();
    }
    else {
        $("#projectBonus").val("0");
        $("#quarterBonus").val("0");
        $("#yearendBonus").val("0");
        $("#otherBonus").val("0");
    }
});

//数据验证
var fnCheckData = function () {

}

//自定义数据保存
var fnCustomSave = function () {
    var url = "../EHR/hrSalaryAjax.aspx?";
    var params = "flag=saveperformancebonus&empId=" + instance[0].EmployeeID;
    params += "&projectBonus=" + instance[0].projectBonus;
    params += "&quarterBonus=" + instance[0].quarterBonus;
    params += "&yearendBonus=" + instance[0].yearendBonus;
    params += "&otherBonus=" + instance[0].otherBonus;
    params += "&year=" + instance[0].year;
    params += "&month=" + instance[0].month;
    params += "&des=" + instance[0].des;
    params += "&r=" + Math.random();
    url += params;
    YAHOO.util.Connect.asyncRequest('POST', url, {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "0") {
                    alert("数据保存成功！");
                }
                else {
                    alert("数据保存失败！");
                }
            }
            catch (e) {
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
        }
    }, null);
}

function ValueChanged() {
    var empId = $("#EmployeeID").val();
    //alert(empId);
    //获取员工编号
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'&r=" + Math.random();
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        if (list.total > 0) {
            for (var o in list.rows) {
                var empcode = list.rows[o].EmployeeCode;
                var dept = list.rows[o].DeptName;
                var post = list.rows[o].PostName;
                if (typeof (empcode) != "undefined") {
                    $("#deptName").val(dept);
                    $("#postName").val(post);
                    $("#empCode").val(empcode);
                    break;
                }
            }
        }
    });
}